﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

using IntrepidGameLibrary;
using IntrepidGameLibrary.Controls;

namespace IntrepidGame.GameScreens
{
    public class NewGameCutscene : BaseGameState
    {
        #region Variables Region

        PictureBox background;

        #endregion

        #region Constructor Region

        public NewGameCutscene(Game game, GameStateManager manager)
            : base(game, manager)
        {
        }

        #endregion

        #region XNA Functions

        public override void  Initialize()
        {
 	        base.Initialize();
        }

        protected override void LoadContent()
        {
            base.LoadContent();

            background = new PictureBox(GameRef.Content.Load<Texture2D>(@"Maps/Map001_large"), GameRef.screenRectangle, GameRef.screenRectangle);
            ControlManager.Add(background);
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            ControlManager.Update(gameTime, playerIndexInControl);


            // THIS
            //
            //
            /* Create a cmera control system that i can se to change the background with the destRectangle using the camera's position*/
            //
            //
            // END THIS
            if (InputHandler.KeyHeld(Keys.Right))
            {
                background.SourceRectangle = new Rectangle((int)MathHelper.Clamp(background.SourceRectangle.X + 32, 0, background.Image.Width - GameRef.screenRectangle.Width), background.SourceRectangle.Y, background.SourceRectangle.Width, background.SourceRectangle.Height);
            }
            if (InputHandler.KeyHeld(Keys.Left))
            {
                background.SourceRectangle = new Rectangle((int)MathHelper.Clamp(background.SourceRectangle.X - 32, 0, background.Image.Width - GameRef.screenRectangle.Width), background.SourceRectangle.Y, background.SourceRectangle.Width, background.SourceRectangle.Height);
            }

            if (InputHandler.KeyHeld(Keys.Down))
            {
                background.SourceRectangle = new Rectangle(background.SourceRectangle.X, (int)MathHelper.Clamp(background.SourceRectangle.Y + 32, 0, background.Image.Height - GameRef.screenRectangle.Height), background.SourceRectangle.Width, background.SourceRectangle.Height);
            }
            if (InputHandler.KeyHeld(Keys.Up))
            {
                background.SourceRectangle = new Rectangle(background.SourceRectangle.X, (int)MathHelper.Clamp(background.SourceRectangle.Y - 32, 0, background.Image.Height - GameRef.screenRectangle.Height), background.SourceRectangle.Width, background.SourceRectangle.Height);
            }

            if (InputHandler.KeyReleased(Keys.Escape))
            {
                StateManager.PushState(GameRef.mainMenu);
            }
        }

        public override void Draw(GameTime gameTime)
        {
            GameRef.spriteBatch.Begin();

            base.Draw(gameTime);

            ControlManager.Draw(GameRef.spriteBatch);

            GameRef.spriteBatch.End();
        }

        #endregion

        #region My Functions

        #endregion
    }
}
